package cn.edu.lzu.dao;

import cn.edu.lzu.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * @PackageName: cn.edu.lzu.dao
 * @InterfaceName: UserMapper
 * @Description: TODO 与user表有关的操作
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2020/2/25 22:14
 * @Version: 1.0
 */
@Mapper
public interface UserMapper {
    //插入在医院挂号的‘挂号信息’
    @Insert("insert into user(user_identity, user_name, email, marital_status, is_deleted, password) values (#{userIdentity}, #{userName}, #{email}, #{maritalStatus}, 0, #{password})")
    int insRegisteUser(User user);

    //用户在线注册

    //根据user_identity查找用户（不管是否被删除——is_deleted==0还是1)
    @Select("select * from user where user_identity=#{userIdentity}")
    User selUserByIdentity(User user);

    @Select("select * from user where user_identity=#{userIdentity} and is_deleted=0")
    User selUserByIdentityAndTrue(String userIdentity);

    //更新is_deleted为0,同时更新其他信息
    @Update("update user set is_deleted=0, user_name=#{userName}, email=#{email}, marital_status=#{maritalStatus}, password=#{password} where user_identity=#{userIdentity}")
    int updDeleteToFasle(User user);

    @Update("update user set telephone=#{telephone}, work_unit=#{workUnit}, education=#{education}, native_place=#{nativePlace}, address=#{address}, nation_id=#{nationId}, occupation=#{occupation} where user_identity=#{userIdentity} and is_deleted=0")
    int updUserBaseMsg(User user);

    @Select("select * from user where user_identity=#{userIdentity} and user_name=#{userName}")
    User selUserByIdentityAndName(String userName, String userIdentity);
}
